package com.higgins.eventtracking.server.dataModel;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.higgins.eventtracking.client.dto.AssetDTO;

@PersistenceCapable
public class Asset {
	@SuppressWarnings("unused")
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	
	@Persistent
	private String account;
	@Persistent
	private Double amount;
	@Persistent
	private String accountType;
	@Persistent
	private String accountRepayment;
	@Persistent
	private Double monthlyRepayment;
	@Persistent
	private Double monthlyInterest;
	@Persistent
	private Date timestamp;
	
	public Asset(Double amount, String account)	{
		this.accountType = "Cash";
		this.amount = amount;
		this.account = account;
		timestamp=new Date();
	}
	public Asset(Double amount, String account, String accountRepayment, Double monthlyRepayment, Double monthlyInterest)	{
		this.accountType = "Loan";
		this.amount = amount;
		this.account = account;
		this.accountRepayment = accountRepayment;
		this.monthlyRepayment = monthlyRepayment;
		this.monthlyInterest = monthlyInterest;
		timestamp=new Date();
	}
	public Asset()	{
		timestamp = new Date();
	}
	public Long getId()	{
		return key.getId();
	}
	public Double getAmount()	{
		return amount;
	}
	public void setAmount(Double amount)	{
		this.amount = amount;
	}
	public String getAccount()	{
		return account;
	}
	public void setAccount(String account)	{
		this.account = account;
	}
	public String getAccountRepayment()	{
		return accountRepayment;
	}
	public void setAccountRepayment(String accountRepayment)	{
		this.accountRepayment = accountRepayment;
	}
	public Double getMonthlyRepayment()	{
		return monthlyRepayment;
	}
	public void setMonthlyRepayment(Double monthlyRepayment)	{
		this.monthlyRepayment = monthlyRepayment;
	}
	public Double getMonthlyInterest()	{
		return monthlyInterest;
	}
	public void setMonthlyInterest(Double monthlyInterest)	{
		this.monthlyInterest = monthlyInterest;
	}
	public AssetDTO toDTO()	{
		AssetDTO assetDTO = new AssetDTO(key.getId(), account, amount, accountType, accountRepayment, 
				monthlyRepayment, monthlyInterest, timestamp);
		return assetDTO;
	}
	public void update(AssetDTO dto)	{
		account = dto.getAccount();
		amount = dto.getAmount();
		accountType = dto.getAccountType();
		accountRepayment = dto.getAccountRepayment();
		monthlyRepayment = dto.getMonthlyRepayment();
		monthlyInterest = dto.getMonthlyInterest();
		timestamp = dto.getTimestamp();
	}
}
